package com.lovo.order.mq;

import com.lovo.common.result.GlobalHandleException;
import com.lovo.common.util.MQUtil;
import com.lovo.order.service.IOrderService;
import com.rabbitmq.client.Channel;
import net.bytebuddy.implementation.bytecode.Throw;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 获取秒杀消息
 */
@Component
@RabbitListener(queues = {"seckill.direct.queue"})
public class SeckillReceiver {
    @Resource
    private IOrderService orderService;
    @Resource
    private MQUtil mqUtil;
    @RabbitHandler
    public void receive(String content, Message message, Channel channel){
        String [] cs = content.split(",");
        try {
            orderService.seckillBuy(Long.parseLong(cs[0]),Long.parseLong(cs[1]));
        } catch (Throwable e) {
            e.printStackTrace();
        }
        mqUtil.ack(message,channel);
    }
}
